package com.zdzx.common.exception;
/*package com.zdzx.common.exception;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintViolationException;
import javax.validation.ValidationException;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import com.zdzx.common.util.Result;
import com.zdzx.common.util.ResultCode;
import com.zdzx.common.util.ResultUtil;
import com.thoughtworks.xstream.core.BaseException;

@ControllerAdvice
public class GlobalExceptionHandler {

	
	@ExceptionHandler(value=MethodArgumentNotValidException.class)
	 @ResponseBody
	 public Result exception(HttpServletRequest request,MethodArgumentNotValidException e){
		 String msg=e.getMessage();
		 if(msg.startsWith("Validation failed for argument")&&msg.contains("default message")) {
			 int indexOf = msg.lastIndexOf("default message");
			 if(indexOf!=-1) {
				 String str=msg.substring(msg.lastIndexOf("[")+1 ,msg.lastIndexOf("]")-1);
					 return ResultUtil.data(ResultCode.RESULT_CHECK.getCode(),str ,null); 
				 
			 }
		 }
	return ResultUtil.data("500",e.getMessage(),null);

	}
	
	 @ExceptionHandler
	    @ResponseBody
	    @ResponseStatus(value=HttpStatus.BAD_REQUEST)
	    public Result handle(ValidationException exception) {
	        if(exception instanceof ConstraintViolationException){
	           String msg=exception.getMessage();
	   		 if(msg.startsWith("Validation failed for argument")&&msg.contains("default message")) {
	   			 int indexOf = msg.lastIndexOf("default message");
	   			 if(indexOf!=-1) {
	   				 String str=msg.substring(msg.lastIndexOf("[")+1 ,msg.lastIndexOf("]")-1);
	   					 return ResultUtil.data(ResultCode.RESULT_CHECK.getCode(),str ,null); 
	   				 
	   			 }
	   		 }
	        }
	        return null;
	    }

}
*/